<template>
  <div>
    <div class="class-list-container" :style="{ height: classList.clsHeight }">
      <div class="class-list">
        <slot></slot>
      </div>
      <div class="cls-lst-hide" @click="openClsBox">
        <span>{{ classList.hideIcon }} {{ classList.clsHide }}</span>
      </div>
    </div>
  </div>
</template>

<script setup>
  import { reactive, onMounted } from 'vue';

  const props = defineProps({
    height: {
      type: String,
      default: '130px',
    },
  });

  let classList = reactive({
    clsHeight: '10px',
    clsHide: '展开所有',
    hideIcon: '▼', 
  });

  const openClsBox = () => {
    if(classList.clsHide === '展开所有') {
      classList.clsHide = '收起';
      classList.hideIcon = '▲';
      classList.clsHeight = 'fit-content';
    } else {
      classList.clsHide = '展开所有';
      classList.hideIcon = '▼';
      classList.clsHeight = props.height;
    }
  };

  onMounted(() => {
    classList.clsHeight = props.height;
  });
</script>

<style lang="scss" scoped>
  .class-list-container{
    position: relative;
    width: 85%;
    margin: auto;
    margin-top: 15px;
    padding: 15px 15px 38px 15px;
    border-radius: 15px;
    box-shadow: 0 0 6px 0 rgba(0, 0, 0, 0.04), 0 4px 8px 8px rgba(0, 0, 0, 0.04), 0 4px 8px 0 rgba(0, 0, 0, 0.08);
    overflow: hidden;
    .cls-lst-hide{
      position: absolute;
      bottom: 0;
      left: 0;
      width: 100%;
      height: 35px;
      line-height: 35px;
      text-align: center;
      font-size: 15px;
      color: $theme-main;
      background-color: white;
      box-shadow: 0 -8px 8px white;
      cursor: pointer;
    }
  }
</style>